import {messages, deepFullCopy} from "share/common";
import React from 'react'
import { connect } from 'react-redux'
import { Form, message, Modal, notification, Popconfirm } from 'antd'
import AddTable from './add-table-cell'
import requestService from 'containers/request/request.service'
import config from 'config'
import httpFetch from 'share/httpFetch'

class GiftRequestDetailC extends React.Component{
  constructor(props) {
    super(props);
    this.state = {
        data: [],
        loading: false,
        valid: true,
        typeKq:'',
        fafangleixing: '',
        selectedRowKeys: [],
        selectedOID: [],
        columns1: [
          {
          title: messages('request.key772'/*礼品*/),
          dataIndex: 'formType',
          width: 70,
          editable: false,
          defaultValue: messages('request.key797'/*BOG*/),
          needFixed: true
        }, {
          title:<div className="red-with-star">{messages('request.key774'/*礼品类型*/)}</div>,
          dataIndex: 'type',
          width: 170,
          editable: true,
          isRequired: true,
          inputType: 'select',
          trueTitle: messages('request.key774'/*礼品类型*/),
          needFixed: true
        }, {
          title: messages('request.key786'/*单张面值*/),
          dataIndex: 'unitPrice',
          width: 115,
          editable: true,
          isReadOnly: true,
          inputType: 'inputNumber',
          needFixed: true
        }, {
          title: <div className="red-with-star">{messages('request.key787'/*申请数量*/)}</div>,
          dataIndex: 'applyQuantity',
          width: 115,
          editable: true,
          isRequired: true,
          inputType: 'inputNumber',
          trueTitle: messages('request.key787'/*申请数量*/),
          needFixed: true
        }, {
          title: messages('request.key788'/*领用数量*/),
          dataIndex: 'receiveQuantity',
          width: 115,
          editable: true,
          isReadOnly: true,
          // isRequired: true,
          inputType: 'inputNumber',
          needFixed: true
        }, {
          title: messages('request.key778'/*金额*/),
          dataIndex: 'amount',
          editable: true,
          isReadOnly: true,
          inputType: 'inputNumber'
        }, {
          title: <div className="red-with-star">{messages('request.key789'/*领用人*/)}</div>,
          dataIndex: 'employeeName',
          width: 110,
          editable: true,
          isRequired: true,
          disabled: false,
          inputType: 'chooser',
          trueTitle: messages('request.key789'/*领用人*/)
        }, {
          title: <div className="red-with-star">{messages('request.key790'/*收货地址*/)}</div>,
          dataIndex: 'address',
          width: 140,
          editable: true,
          isRequired: true,
          inputType: 'select',
          trueTitle: messages('request.key790'/*收货地址*/)
        }, {
          title: <div className="red-with-star">{"手机号码"}</div>,
          dataIndex: 'contactWay',
          width: 130,
          editable: true,
          isRequired: true,
          trueTitle: "手机号码"
        }, {
          title: <div className="red-with-star">{'省份'}</div>,
          dataIndex: 'province',
          width: 130,
          editable: true,
          isReadOnly: true,
          isRequired: true,
          trueTitle: '省份'
        },
        {
          title: <div className="red-with-star">{'城市'}</div>,
          dataIndex: 'city',
          width: 130,
          editable: true,
          isReadOnly: true,
          isRequired: true,
          trueTitle: '城市'
        },
        {
          title: <div className="red-with-star">{'区县'}</div>,
          dataIndex: 'districtsAndCounties',
          width: 130,
          editable: true,
          isReadOnly: true,
          isRequired: true,
          trueTitle: '区县'
        },
        {
          title: <div className="red-with-star">{'详细地址'}</div>,
          dataIndex: 'detailedAddress',
          width: 130,
          editable: true,
          isReadOnly: true,
          isRequired: true,
          trueTitle: '详细地址'
        },
        {
          title: <div className="red-with-star">{'邮政编码'}</div>,
          dataIndex: 'postalCode',
          width: 130,
          editable: true,
          isReadOnly: true,
          isRequired: true,
          trueTitle: '邮政编码'
        },],
        columns2: [{
          title: messages('request.key791'/*券号信息*/),
          dataIndex: 'cardNumber',
          width: 150,
          editable: false,
          isRequired: true
        },
        {
          title: '发货状态',
          dataIndex: 'distributionStatus',
          width: 130,
          editable: false,
          trueTitle: '发货状态'
        },
        // {
        //   title: messages('request.key792'/*发放方式*/),
        //   dataIndex: 'sendWayText',
        //   width: 100,
        //   editable: false,
        //   isRequired: true,
        //   inputType: 'select'
        // },
        {
          title: '快递公司',
          dataIndex: 'deliveryCompany',
          width: 100,
          editable: false,
        },

        {
          title: messages('request.key793'/*快递信息*/),
          dataIndex: 'deliveryInfo',
          width: 100,
          editable: false,
          isRequired: true
        },
        // {
        //   title: messages('request.key794'/*联系人*/),
        //   dataIndex: 'link',
        //   width: 100,
        //   editable: false,
        //   isRequired: true
        // }, {
        //   title: messages('request.key795'/*电话*/),
        //   dataIndex: 'phone',
        //   width: 130,
        //   editable: false,
        //   isRequired: true
        // }, {
        //   title: messages('request.key796'/*附件*/),
        //   dataIndex: 'appendix',
        //   width: 200,
        //   editable: false,
        //   inputType: 'upload'
        // },
        {
          title: '签收状态',
          dataIndex: 'signingStatus',
          width: 100,
          editable: false,
        },
        // {
        //   title: <div className="red-with-star">{'发放类型'}</div>,
        //   dataIndex: 'releaseType',
        //   width: 100,
        //   editable: true,
        //   isRequired: true,
        //   inputType: 'select',
        //   trueTitle: '发放类型'
        // },
        {
          title: '行号',
          dataIndex: 'lineNo',
          // width: 70,
          editable: false,
        },
      ],
        isInfo: false,
        info: {},
        dataC: []
    }
  }

  componentWillReceiveProps (nextProps) {
    let custFormValues = nextProps.info.custFormValues
    let custFormValuesJson = {}
    custFormValues && custFormValues.map(item => {
      custFormValuesJson[item.fieldCode] = item
    })
    let fafangleixing = '';
    if(custFormValuesJson.kq){
      if(custFormValuesJson.kq.value === "002"){
        fafangleixing = custFormValuesJson.fafangleixing.value
      }
    }
    if(fafangleixing!== this.state.fafangleixing ){
      this.setState({fafangleixing},()=>{
        this.getTableList()
      })
    }
    if(custFormValuesJson.kq){
      if(custFormValuesJson.kq.value!== this.state.typeKq ){
        this.setState({typeKq: custFormValuesJson.kq.value, info: this.props.info},()=>{
          this.getGiftCardType()
          this.giftsendWayList()
          this.giftAddressList()
        })
      }
    }
    if (this.state.info !== nextProps.info && this.props.totalAmount !== nextProps.totalAmount) {
      this.getTableList()
    }
    this.updateFiledTitle()
    this.setState({
      info: nextProps.info
    })
  }

  componentDidMount () {
    this.props.onRef(this)

    let custFormValues = this.props.info.custFormValues
    let custFormValuesJson = {}
    custFormValues && custFormValues.map(item => {
      custFormValuesJson[item.fieldCode] = item
    })
    let fafangleixing = '';
    if(custFormValuesJson.kq){
      if(custFormValuesJson.kq.value === "002"){
        fafangleixing = custFormValuesJson.fafangleixing.value
      }
    }
    if(custFormValuesJson.kq){
      this.setState({typeKq: custFormValuesJson.kq.value, fafangleixing, info: this.props.info},()=>{
        // if(custFormValuesJson.kq.value === '002'){this.getReleaseType ()}
        this.getGiftCardType()
        this.giftsendWayList()
        this.giftAddressList()
        this.getTableList()
      })
    }else {
      this.setState({info: this.props.info})
      this.getGiftCardType()
      this.giftsendWayList()
      this.giftAddressList()
      this.getTableList()
    }
  }

  isElectronic(){
    const kq = this.props.info.custFormValues.find(i=> i.fieldCode=== 'kq')
    return kq && kq.value === '002'
  }
  isFafangleixingEq002(){
    const f = this.props.info.custFormValues.find(i=> i.fieldCode=== 'fafangleixing')
    // 001 直发，002派发
    return f && f.value === '002'
  }

  updateFiledTitle(){
    const title = (this.isElectronic() && this.isFafangleixingEq002()) ? '发放状态' : '发货状态'
    const columns2 = this.state.columns2.map(i => {
      if (i.dataIndex === 'distributionStatus') {
        i.title = title
        i.trueTitle = title
        return i
      } else return i
    })
    this.setState({
      columns2: columns2
    })
  }

  // 获取当前表格的列表数据
  getTableList () {
    const {id, type} = this.props;
    this.setState({
      loading: true
    }, () => {
      requestService.getGiftRequestDetail(id, 3).then(res => {
        let data = deepFullCopy(res.data)
        const newData = data.map((item, index) => {
          item.key = index + 1
          item.formType = messages('request.key797'/*BOG*/)
          item.appendix = eval(item.appendix)
          return item
        })
        this.setState({
          data: newData,
          loading: false,
          dataC: res.data
        })
        if (type) {
          this.props.isCallBack({
            giftC: res.data,
            code: 'giftC'
          })
        }
      })
    })
  }

  // 获取礼品卡类型值列变OID以及获取礼品卡类型的数据
  getGiftCardType () {
    const isElectronic = this.state.typeKq;
    requestService.getGiftCardType(3, isElectronic).then(res => {
      let customEnumerationOID = res.data[0].customEnumerationOID
      requestService.getGiftCardTypeList(customEnumerationOID).then(data => {
        const {columns1} = this.state
        columns1.map(item => {
          if (item.dataIndex === 'type') {
            item.value = data.data.values
          }
        })
        this.setState({
          columns1
        })
      })
    })
  }

  // 获取发放方式的值列表OID以及获取发放方式的数据
  giftsendWayList () {
    requestService.getGiftCardType(5).then(res => {
      let customEnumerationOID = res.data[0].customEnumerationOID
      requestService.getGiftCardTypeList(customEnumerationOID).then(data => {
        const {columns2} = this.state
        columns2.map(item => {
          if (item.dataIndex === 'sendWayText') {
            item.value = data.data.values
          }
        })
        this.setState({
          columns2
        })
      })
    })
  }

  // 获取地址的值列表OID以及获取地址的数据
  giftAddressList () {
    requestService.getGiftCardType(6).then(res => {
      let customEnumerationOID = res.data[0].customEnumerationOID
      requestService.getGiftCardTypeList(customEnumerationOID).then(data => {
        const {columns1} = this.state
        columns1.map(item => {
          if (item.dataIndex === 'address') {
            item.value = data.data.values
          }
        })
        this.setState({
          columns1
        })
      })
    })
  }

   // 获取发放类型的值列表OID以及获取发放类型的数据
   getReleaseType () {
    requestService.getGiftCardType(10).then(res => {
      let customEnumerationOID = res.data[0].customEnumerationOID
      requestService.getGiftCardTypeList(customEnumerationOID).then(data => {
        const {columns2} = this.state
        columns2.map(item => {
          if (item.dataIndex === 'releaseType') {
            item.value = data.data.values
          }
        })
        this.setState({
          columns2
        })
      })
    })
  }

  // 增加
  // isInfo是控制用户在第一次点击增加的时候，提醒用户在申请前需要与销售中心确认申请数量
  handleOnAdd = (e) => {
    if(this.props.editLines){
      message.warning('已有一行正在编辑')
      return;
    }
    this.props.onChangeEdit(true);
    // const {isInfo} = this.state
    // if (!isInfo) {
    //   message.warning(messages('request.key798'/*请在申请前与销售中心确认申请数量。*/))
    //   this.setState({
    //     isInfo: true
    //   })
    // }
    let { info, data=[]} = this.state;
    let lineSumVaild = this.props.lineSumChange()
    if(lineSumVaild){
      return;
    }
    if (info.formCode === 'SQ002'){ //礼品申请单不带出历史地址
      const autoPhoneNumber=this.isElectronic() && this.isFafangleixingEq002()
      let obj = {
        fullName: info.applicant.fullName,
        employeeID: info.applicant.employeeID,
        contactWay: autoPhoneNumber?info.applicant.mobilePhoneNumber:undefined,
      }
      this.child.handleAdd(obj)
    }else if(info.formCode === 'SQ004'){
      // 以下为参考礼品单逻辑
      let obj = {
        fullName: info.applicant.fullName,
        employeeID: info.applicant.employeeID,
      }
      // 以下是33行校验
      if(data.length>=30){
        message.warning('当前单据申请行总行数数量必须≤30行')
        return
      }else{
        this.child.handleAdd(obj)
      }
    } else {
      if (this.state.data.length === 0) {
        // Modal.confirm({
        //   title: '请在申请前与销售中心确认申请数量，以免库存不足影响发放。',
        //   onOk: () => {
        let obj = {
          fullName: info.applicant.fullName,
          employeeID: info.applicant.employeeID,
        }
        this.child.handleAdd(obj)
        //   },
        //   onCancel() {},
        // })
      } else if (this.state.data && this.state.data.length > 0) {
        let obj = {
          address:  this.state.data[0].address,
          contactWay: this.state.data[0].contactWay,
          employeeID: this.state.data[0].employeeId,
          fullName: this.state.data[0].employeeName,
        }
        this.child.handleAdd(obj)
      } else {
        this.child.handleAdd()
      }
    }
  }

  // 删除
  onDelete = (record) => {
    const { data, dataC } = this.state
    if (record.id) {
      requestService.giftRequestDetailTableDelete(record.id).then(res => {
        if (res.data) {
          this.setState({
            data: data.filter(item => item.key !== record.key),
            dataC: dataC.filter(item => item.id !== record.id)
          },() => {
            message.success(messages('request.key780'/*删除成功*/))
            this.props.isCallBack(true)
          })
        }
      })
    } else {
      this.setState({ data: data.filter(item => item.key !== record.key) },() => {
        message.success(messages('request.key780'/*删除成功*/))
      })
    }
  }

  // 保存
  onSave = (value) => {
    let { info, typeKq } = this.state
    const { record, index, row } = value
    let json = {
      ...record,
      ...row
    }
    let needRepeat = false;
    json.formType = 3
    json.appendix = json.appendix ? JSON.stringify(json.appendix) : '[]'
    if (['SQ021', 'SQ023'].includes(info.formCode)) {
      json.sendWayText = row.sendWayText.split(',')[0] ? row.sendWayText.split(',')[0] : json.sendWayText
      json.sendWay = row.sendWayText.split(',')[2] ? row.sendWayText.split(',')[2] : json.sendWay
      if (json.sendWayText === '自取') {
        json.deliveryInfo = ''
      }
      let receiveQuantity = Number(json.receiveQuantity)
      let applyQuantity = Number(json.applyQuantity)
      if (receiveQuantity <= applyQuantity && receiveQuantity > 0) {
        json.amount = receiveQuantity * Number(json.unitPrice)
      } else {
        message.info('领用数量不能大于申请数量并且不能等于0')
        return
      }
    } else {
      json.type = row.type ? row.type.split(',')[0] : undefined
      json.address = row.address ? row.address.split(',')[0] : undefined
      json.employeeName = (row.employeeName && row.employeeName[0].fullName) ? row.employeeName[0].fullName : json.employeeName
      json.employeeId = (row.employeeName && row.employeeName[0].employeeID) ? row.employeeName[0].employeeID: json.employeeId
    }
    this.setState({loading: true})
    this.state.data && this.state.data.map((item, indexB) => {
      if (index !== indexB) {
        if(typeKq === '001'||['SQ004'].includes(info.formCode)){
          if (item.type === json.type && item.address === json.address) {
            needRepeat = true;
          }
        }else{
          if (item.type === json.type) {
            needRepeat = true;
          }
        }
      }
    })
    if (needRepeat) {
      message.warning("该礼品已添加")
      this.setState({loading: false})
      return
    }
    json.phone = json.phone ? json.phone.trim() : undefined;
    if(json.releaseType){
      json.releaseType = json.releaseType.split(',')[0]
    }
    json.address = json.address ||  '-'
    if (record.id) {// 编辑的保存
      requestService.giftRequestDetailTableEdit(json).then(res => {
        let data = deepFullCopy(res.data)
        data.formType = messages('request.key797'/*BOG*/)
        this.onSaveFunc(record, index, data, res.data )
        message.success(messages('request.key779'/*保存成功*/))
      }).catch(() => {
        this.setState({loading: false})
      })
    } else {
      const {formOID, id} = this.props;
      json.formOid = formOID
      json.applicationId = id
      requestService.giftRequestDetailTableAdd(json).then(res => {
        let data = deepFullCopy(res.data)
        data.formType = messages('request.key797'/*BOG*/)
        this.onSaveFunc(record, index, data, res.data )
        message.success(messages('request.key779'/*保存成功*/))
      }).catch(() => {
        this.setState({loading: false})
      })
    }
  }

  // 保存之后的回调
  onSaveFunc(record, index, row, data ) {
    const newData = [...this.state.data];
    const newDataC = [...this.state.dataC];
    row.key = new Date().getTime();
    newData.splice(index, 1, {
      ...record,
      ...row,
      appendix: eval(row.appendix) || []
    })
    newDataC.splice(index, 1, data)
    this.setState({
      data: newData,
      loading: false,
      dataC: newDataC
    })
    this.child.cancel()
    this.props.onChangeEdit(false);
    this.props.isCallBack(true)
  }

  // 子组件修改父组件的数据
  onChange = (value) => {
    this.setState({
      data: value
    })
  }

   //选中项发生变化的时的回调
   onSelectChange = (selectedRowKeys) => {
    this.setState({ selectedRowKeys })
  };

  //选择/取消选择某行的回调
  handleSelectRow = (record, selected) => {
    let selectedOID = this.state.selectedOID;
    if (selected) {
      selectedOID.push(record)
    } else {
      selectedOID.delete(record)
    }
    let valid = false
    if(selectedOID.length == 0){
      valid = true
    }
    selectedOID.forEach(i => {
      if(i.distributionStatus != '已发货'){
        valid =true
      }
      if(i.signingStatus != '待签收'){
        valid =true
      }
    })
    if(valid){
      this.setState({valid})
    }else{
      this.setState({valid:false})
    }
    this.setState({ selectedOID })
  };

  //选择/取消选择所有行的回调
  handleSelectAllRow = (selected, selectedRows, changeRows) => {
    let selectedOID = this.state.selectedOID;
    if(selected) {
      changeRows.map(item => {
        selectedOID.push(item)
      })
    } else {
      changeRows.map(item => {
        selectedOID.delete(item)
      })
    }
    let valid =false
    if(selectedOID.length == 0){
      valid = true
    }
    selectedOID.forEach(i => {
      if(i.distributionStatus != '已发货'){
        valid =true
      }
      if(i.signingStatus != '待签收'){
        valid =true
      }
    })
    if(valid){
      this.setState({valid})
    }else{
      this.setState({valid:false})
    }
    this.setState({ selectedOID })
  };

  onBatchConfirm = () => {
    this.setState({loading : true});
    const selectData =  this.state.selectedOID;
    let valid = false;
    if(selectData.length==0){
      message.warning('请选择一条数据');
      this.setState({loading : false});
      return;
    }
    try {
      selectData.forEach(i => {
        if(i.distributionStatus != '已发货'){
          valid =true;
          message.warning(`${i.formType==2 ? '礼品卡' : i.formType==3 ? 'BOG' : '现金券'}${i.type}未发货`);
          throw Error();
        }
        if(i.signingStatus != '待签收'){
          valid =true;
          message.warning(`${i.formType==2 ? '礼品卡' : i.formType==3 ? 'BOG' : '现金券'}${i.type}${i.signingStatus}`);
          throw Error();
        }
      })
    } catch(e){
    }
    if(valid){
      this.setState({loading : false});
      return;
    }
    let data = [];
    selectData.forEach(i => {
      let item = {
        businessCode: i.lineNo.split('-')[0],
        lineCode: i.lineNo,
        state: 'hand_signed',
      }
      data.push(item);
    })
    httpFetch.post(`${config.baseUrl}/api/bath/send/ecs/active?roleType=TENANT`, data).then(res => {
      if(res.data.success){
        message.success('卡券激活成功');
        this.setState({loading : false});
        this.props.isCallBack(true);
        this.getTableList();
      }else{
        message.error(`卡券激活失败，请稍后重试`)
        this.setState({loading : false});
      }
    }).catch((e) => {
      this.setState({loading: false})
      errorMessage(e.response);
    })

  }

  onBatchLose = () => {
    this.setState({loading : true});
    const selectData =  this.state.selectedOID;
    let valid = false;
    if(selectData.length==0){
      message.warning('请选择一条数据');
      this.setState({loading : false});
      return;
    }
    try {
      selectData.forEach(i => {
        if(i.distributionStatus != '已发货'){
          valid =true;
          message.warning(`${i.formType==2 ? '礼品卡' : i.formType==3 ? 'BOG' : '现金券'}${i.type}未发货`);
          throw Error();
        }
        if(i.signingStatus != '待签收'){
          valid =true;
          message.warning(`${i.formType==2 ? '礼品卡' : i.formType==3 ? 'BOG' : '现金券'}${i.type}${i.signingStatus}`);
          throw Error();
        }
      })
    } catch(e){
    }
    if(valid){
      this.setState({loading : false});
      return;
    }
    let data = [];
    selectData.forEach(i => {
      let item = {
        businessCode: i.lineNo.split('-')[0],
        lineCode: i.lineNo,
        state: 'hand_lost',
      }
      data.push(item);
    })
    httpFetch.post(`${config.baseUrl}/api/bath/send/ecs/invalid?roleType=TENANT`, data).then(res => {
      if(res.data.success){
        message.success('卡券作废成功');
        this.setState({loading : false});
        this.props.isCallBack(true);
        this.getTableList();
      }else{
        message.error(`卡券作废失败，请稍后重试`)
        this.setState({loading : false});
      }
    }).catch((e) => {
      this.setState({loading: false})
      errorMessage(e.response);
    })
  }

  onConfirm = (i) => {
    this.setState({loading : true});
    let valid = false;
    if(i.distributionStatus != '已发货'){
      valid =true;
      message.warning('卡券未发放');
    }
    if(i.signingStatus == '已签收' || i.signingStatus == '已遗失'){
      valid =true;
      message.warning('卡券已签收/已遗失');
    }
    if(valid){
      return;
    }
    let data= {
      businessCode: i.lineNo.split('-')[0],
      lineCode: i.lineNo,
      state: 'hand_signed',
    }
    httpFetch.post(`${config.baseUrl}/api/send/ecs/active?roleType=TENANT`,data).then(res => {
      if(res.data.success){
        message.success('卡券激活成功');
        this.setState({loading : false});
        this.props.isCallBack(true);
        this.getTableList();
      }else{
        message.error(`卡券激活失败，请稍后重试`)
        this.setState({loading : false});
      }
    }).catch((e) => {
      this.setState({loading: false})
      errorMessage(e.response);
    })
  }

  onLose = (i) => {
    this.setState({loading : true});
    let valid = false;
    if(i.distributionStatus != '已发货'){
      valid =true;
      message.warning('卡券未发放');
    }
    if(i.signingStatus == '已签收' || i.signingStatus == '已遗失'){
      valid =true;
      message.warning('卡券已签收/已遗失');
    }
    if(valid){
      return;
    }
    let data= {
      businessCode: i.lineNo.split('-')[0],
      lineCode: i.lineNo,
      state: 'hand_lost',
    }
    httpFetch.post(`${config.baseUrl}/api/send/ecs/invalid?roleType=TENANT`, data).then(res => {
      if(res.data.success){
        message.success('卡券作废成功');
        this.setState({loading : false});
        this.props.isCallBack(true);
        this.getTableList();
      }else{
        message.error(`卡券作废失败，请稍后重试`)
        this.setState({loading : false});
      }
    }).catch((e) => {
      this.setState({loading: false})
      errorMessage(e.response);
    })
  }

  render() {
    const { data, loading, columns1, columns2, info, typeKq, selectedRowKeys, fafangleixing } = this.state
    const { isDoneApproved, approve, costApplication } = this.props;
    let isEditFlag = ['10011000', '10011001', '10011002'].includes(`${info.status}${info.rejectType}`)
    let {applicationParticipant, approvalChain:{brmsRemark}={}} = info
    let closed = applicationParticipant && applicationParticipant.closed
    const isEdit = isEditFlag && ['SQ002', 'SQ004'].includes(info.formCode) ? isDoneApproved && isDoneApproved === 'true' ? false : true : false
    const isContentEdit = isEditFlag && `${closed}` !== '1' ? isDoneApproved && isDoneApproved === 'true' ? false : true : false
    const isDeleteBtnFlag = isEditFlag && ['SQ021', 'SQ023'].includes(info.formCode) ? true : false
    let custFormValues = info.custFormValues
    let custFormValuesJson = {}
    custFormValues && custFormValues.map(item => {
      custFormValuesJson[item.fieldCode] = item
    })
    const isCLBtn = typeKq === '001' && info.status != '1001' && !costApplication &&(brmsRemark==='确认签收/遗失'||!approve)
    //  && approve;
    let newColumns1 = [];
    let newColumns2 = [];
    if(typeKq === '002'){ //卡券类型为电子卡券
      newColumns1 =columns1.filter(item => ['address', 'province', 'city', 'districtsAndCounties', 'detailedAddress', 'postalCode'].includes(item.dataIndex) != true );
      newColumns2 =columns2.filter(item => ['deliveryInfo', 'signingStatus','deliveryCompany'].includes(item.dataIndex) != true );
    } else {
      newColumns2 =columns2.filter(item => ['releaseType'].includes(item.dataIndex) != true );
    }
    if (isDeleteBtnFlag) {
      columns1.map(item => {
        item.editable = false
        if (item.dataIndex === 'receiveQuantity') {
          item.editable = true
          item.isReadOnly = false
        }
        item.title = item.trueTitle ? item.trueTitle : item.title
        if (item.dataIndex === 'receiveQuantity') {
          // if (['SQ021', 'SQ022', 'SQ023'].includes(info.formCode)) {
          //   item.title = messages('request.key788'/*领用数量*/)
          // } else {
            item.title = <div className="red-with-star">{messages('request.key788'/*领用数量*/)}</div>
            item.trueTitle = messages('request.key788'/*领用数量*/)
            item.isRequired = true
          // }
        }
      })
      columns2.map(item => {
        item.editable = true
        if (['cardNumber', 'sendWayText', 'link', 'phone'].includes(item.dataIndex)) {
          // if (['SQ021', 'SQ022', 'SQ023'].includes(info.formCode)) {
          //   item.isRequired = false;
          // } else {
            item.trueTitle = item.title;
            item.title = <div className="red-with-star">{item.trueTitle}</div>
          }
        // }
      })
    }
    if(typeKq === '002' && fafangleixing === '002'){
      columns1.map(item => {
        if (item.dataIndex === 'employeeName') {
          item.disabled = true
        }
      })
    }else{
      columns1.map(item => {
        if (item.dataIndex === 'employeeName') {
          item.disabled = false
        }
      })
    }
    let columns = typeKq !== '002' ? [...columns1, ...newColumns2] : [...newColumns1, ...newColumns2]
    if(typeKq === '002'){
      if(fafangleixing === '002'){
        columns = columns.filter(item => ['formType', 'type', 'unitPrice', 'applyQuantity', 'receiveQuantity', 'amount', 'employeeName', 'contactWay', 'distributionStatus', 'lineNo'].includes(item.dataIndex)).map(i=> {
          if(['contactWay'].includes(i.dataIndex)) {
            return {...i,
              isReadOnly:  true,
              isRequired:  false,
            }
          }
          return i
        })
      }else{
        columns = columns.filter(item => ['formType', 'type', 'unitPrice', 'applyQuantity', 'receiveQuantity', 'amount'].includes(item.dataIndex))
      }
    }
    const rowSelection = {
      selectedRowKeys: selectedRowKeys,
      onChange: this.onSelectChange,
      onSelect: this.handleSelectRow,
      onSelectAll: this.handleSelectAllRow
    };
    return (
      <div className="request-info">
        <div className="tab-container">
            <h3 className="sub-header-title">
              {messages('request.key762'/*申请单行信息*/)}
              {
                isEdit && (<span className="sub-header-title-edit" onClick={this.handleOnAdd}>{messages('request.key763'/*+新增*/)}</span>)
              }
              {
                isCLBtn && (
                  <Popconfirm title="是否确认签收?" onConfirm={() => this.onBatchConfirm()}>
                      <a disabled={this.state.valid} style={{ marginLeft: 10 , fontSize:5 }}>勾选签收</a>
                  </Popconfirm>
                )
              }
              {
                isCLBtn && (
                  <Popconfirm  title="是否确认遗失?" onConfirm={() => this.onBatchLose()}>
                      <a disabled={this.state.valid} style={{ marginLeft: 10, fontSize:5 }}>勾选遗失</a>
                  </Popconfirm>
                )
              }
            </h3>
            <AddTable
                onRef={ref => this.child = ref}
                value={data}
                isEdit={isContentEdit}
                isCancleDeleteBtn={isDeleteBtnFlag}
                loading={loading}
                operationKey={"addTableC"}
                columns={columns}
                onDelete={this.onDelete}
                onChange={this.onChange}
                onSave={this.onSave}
                onConfirm={this.onConfirm}
                onLose={this.onLose}
                isCLBtn={isCLBtn}
                rowSelection={rowSelection}
                editLines={this.props.editLines}
                onChangeEdit={this.props.onChangeEdit}
                fafangleixing={fafangleixing}
                info={info}
                title={() => (<div className="sub-header-giftRequestDetail-title">{messages('request.key783'/*C BOG*/)}</div>)}
            />
        </div>
      </div>
    )
  }
}

GiftRequestDetailC.contextTypes = {
  router: React.PropTypes.object
};

function mapStateToProps() {
  return { }
}

const wrappedGiftRequestDetailC = Form.create()(GiftRequestDetailC);

export default connect(mapStateToProps)(wrappedGiftRequestDetailC)
